package com.six.goods.controller;

import com.github.pagehelper.PageInfo;
import com.six.core.entity.Goods;
import com.six.core.vo.GoodsVo;
import com.six.core.vo.Result;
import com.six.goods.service.GoodsService;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: whj
 * @Version 1.0
 * @Date: 2023/2/27  10:00
 */
@RestController
@RequestMapping("/goods/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    //商品列表--分页
    @PostMapping("/listpaging")
    @ResponseBody
    public Result listpaging(@RequestParam(defaultValue = "1")Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize, @RequestBody GoodsVo goodsVo){
        return goodsService.seleAllGoods(currentPage,pageSize,goodsVo);
    }
    //商品列表--分页---pageinfo
    @PostMapping("/lising")
    @ResponseBody
    public PageInfo lising(@RequestParam(defaultValue = "1")Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize, @RequestBody GoodsVo goodsVo){
        return goodsService.seleGoods(currentPage,pageSize,goodsVo);
    }

    //修改状态--上下架--商品列表
    @PostMapping("/upstate")
    @ResponseBody
    public Result upstate(@RequestBody Goods goods){
        return goodsService.updateState(goods);
    }



    //商品审核--分页
    @PostMapping("/checkpaging")
    @ResponseBody
    public Result checkpaging(@RequestParam(defaultValue = "1")Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize, @RequestBody GoodsVo goodsVo){
        return goodsService.queryGood(currentPage,pageSize,goodsVo);
    }

    //前端--所有商品展示--分页
    @PostMapping("/selectBycategoryid")
    @ResponseBody
    public Result selectBycategoryid(@RequestParam(defaultValue = "1")Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize,@RequestBody GoodsVo goodsVo){
        return goodsService.selectGoodsByCatrgotyId(currentPage,pageSize,goodsVo);
    }
    //前端--所有商品展示--分页
    @PostMapping("/selectBycategory")
    @ResponseBody
    public Result selectBycategory(@RequestParam(defaultValue = "1")Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize,@RequestBody GoodsVo goodsVo){
        return goodsService.selectGoodsByCatrgoty(currentPage,pageSize,goodsVo);
    }

    //根据id查询商品所有信息
    @PostMapping("/selectGoodsByid/{id}")
    @ResponseBody
    public Result selectGoodsByid(@PathVariable Integer id){
        return goodsService.goodsbyids(id);
    }

    //前端--商家登录--商品管理
    @PostMapping("/selectAllGoodsByshopid")
    @ResponseBody
    public Result selectAllGoodsByshopid(@RequestParam(defaultValue = "1")Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize,@RequestBody GoodsVo goodsVo){
        return goodsService.selectAllGoodsByshopid(currentPage,pageSize,goodsVo);
    }

    //前端--商家登录--添加商品
    @PostMapping("insertGoods")
    public Result insertGoods(@RequestBody Goods goods){
        return goodsService.insertGoodsOne(goods);
    }

    //前端--商家登录--商家上下架商品
    @PostMapping("/soldout")
    public Result soldout(@RequestBody Goods goods){
        return goodsService.soldout(goods);
    }

    //前端--商家登录--商家删除商品
    @PostMapping("/deteleGoods")
    public Result deteleGoods(Integer id){
        return goodsService.deteleGoods(id);
    }

    //前端--商家登录--商家修改商品
    @PostMapping("/updateGoods")
    public Result updateGoods(@RequestBody Goods goods){
        return goodsService.updateGoods(goods);
    }

    //根据商店id查询店铺商品
    @GetMapping("/selectByshopid")
    public Result selectByshopid(@RequestParam(defaultValue = "1")Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize, Integer shopid){
        return goodsService.selectByshopid(currentPage,pageSize,shopid);
    }
    //根据商店id查询店铺商品
    @GetMapping("/selectByshopid1")
    public Result selectByshopid1(Integer shopid){
        return goodsService.selectByshopid1(shopid);
    }
}

